<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .todolist{
            width: 1200px;
            height: 600px;
            box-shadow:0 7px 17px rgb(0 0 0 / 20%);
            margin: 10px auto;
        }
        .todohead{
            height: 60px;
            background-color: #c1bcb5;
        }
        .todohead >input{
            width: 70%;
            height: 40px;
            margin: 10px 10px 0 140px;
            border-radius: 10px;
            border: none;
            outline: none;
        }
        .todohead >button{
            height: 40px;
            border-radius: 10px;
            font-size: 24px;
            background-color: #717575;
            border: none;
            color: #d4d0d0;
            outline: none;
        }
        .todobody{
            width: 1100px;
            margin: 0 auto;
        }
        .row{
            height: 40px;
            display: flex;
            justify-content: space-between;
            line-height: 40px;
        }
        ul > li{
            list-style: none;
        }
        .yes:hover{
            display: inline;
        }
        .img:hover{
            background: url(./yesRed.png);
        }
        .del:hover{
            font-size: 26px;
        }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app"></div>
    <script>
        let app = {
            template:` 
                <div class="todolist">
                     <div class="todohead" >
                        <input v-model="inputValue" @keyup.enter="send">
                        <button @click="send">send out</button>
                    </div>
                    <div class="todobody">
                        <ul class="row" v-for="(item, index ) in arr" >
                            <li class="yes">
                                <img class="img" @click="changeImg(item)" :src="item.imgUrl">
                                </li>
                            <li >{{item.title}}</li>
                            <li class="del" @click="dele(index)">x</li>
                        </ul>
                    </div>
                </div>
            `,
            data(){
                return{
                    arr:[],
                    arr2:[],
                    inputValue:'',
                    imgUrl:'./yes.png',
                }
            },
            created(){
                this.active();
            },
            methods:{
                dele(index){
                    this.arr.splice(index,1);
                    localStorage.setItem('arr',JSON.stringify(this.arr));
                },
                changeImg(item){
                    if(item.imgUrl == './yesRed.png'){
                        item.imgUrl = './yes.png';
                        item.flag = false
                    }else{
                        item.imgUrl = './yesRed.png';
                        item.flag = true
                    }
                },
                send(){
                    if(this.inputValue===''){
                        alert('请输入任务内容')
                    }else{
                        this.arr.unshift({
                        imgUrl:this.imgUrl,
                        title:this.inputValue,
                        flag:false
                    });
                    localStorage.setItem('arr',JSON.stringify(this.arr));
                    this.inputValue='';
                    }
                },
                active(){
                    console.log(this.arr)
                    if(JSON.parse(localStorage.getItem('arr')) == null){
                        console.log('暂时还没有任务哦')
                    }else{
                        this.arr=JSON.parse(localStorage.getItem('arr'))
                    }
                }
            }
        }
        new Vue({
            render:function(h){
                return h(app)
            }
        }).$mount('#app')
    </script>
</body>
</html>